'''Created on 15-05-2012

@author: ahaw
'''
import os

import sys
from PyQt4 import QtGui,QtCore
class Settings(QtCore.QSettings):
    '''
    Klasa zawierająca ustawienia programu.
    '''
    def __init__(self,*args):
        super(QtCore.QSettings, self).__init__()
        
        '''
        kontruktor wraz ze standardowymi ustawieniami programu
        '''
        Settings.instance=self
        self.playlistsDirectory="/home/ahaw/.config/PyMP/playlists/"
        self.setValue("general/databaseDirectory", os.getenv('HOME') + '/.config/PyMP/');
        self.setValue("general/editState", False);        
        Settings.configDir = self.value('general/databaseDirectory')
        Settings.editState = self.value('general/editState')
        Settings.libraryDirectories=[]        #self.setValue("general/libraryLocation")
        size = self.beginReadArray("library/libraryLocations")
        for i in range(0, size):
            self.setArrayIndex(i);
            Settings.instance.libraryDirectories.append( self.value("path"))
        self.endArray()
    

    def addDirectory(self,directory):
        '''
        Dodawanie katalogu do listy katalogow
        '''
        if directory not in Settings.instance.libraryDirectories:
            Settings.instance.libraryDirectories.append(directory)
        Settings.saveSettings(Settings.instance)    
    def saveSettings(self):
        '''
        Zapisywanie ustawien programu
        '''
        self.remove("library/libraryLocations")
        self.beginWriteArray("library/libraryLocations")
        for i in range(0, len(Settings.libraryDirectories)):
            self.setArrayIndex(i)
            self.setValue("path", Settings.libraryDirectories[i])
        self.endArray()
        self.sync()
def main():                   

    app = QtGui.QApplication(sys.argv)
    app.setOrganizationName('PyMP')
    app.setApplicationName("PyMp - Python Music Player")
    Settings()
    
    
if __name__ == '__main__':
    main()